package com.dreamwhale.machinery.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamwhale.machinery.user.entity.YxUserAddress;
import com.dreamwhale.machinery.user.mapper.YxUserAddressMapper;
import com.dreamwhale.machinery.user.service.YxUserAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 用户地址表 服务实现类
 * </p>
 *
 * @author Author
 * @since 2020-05-27
 */
@Service
public class YxUserAddressServiceImpl extends ServiceImpl<YxUserAddressMapper, YxUserAddress> implements YxUserAddressService {

    @Resource
    private YxUserAddressMapper yxUserAddressMapper;

    @Override
    public int insertYxUserAddress(YxUserAddress yxUserAddress) {
        yxUserAddress.setAddTime(LocalDateTime.now());
        return yxUserAddressMapper.insert(yxUserAddress);
    }

    @Override
    public int selectYxUserAddress(Integer userId) {
        QueryWrapper<YxUserAddress> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid", userId).eq("is_default", 0).eq("is_del", 0);
        List<YxUserAddress> list = yxUserAddressMapper.selectList(queryWrapper);
        if (list.size() > 0) {
            return 1;
        }
        return 0;
    }

    @Override
    public int updateYxUserAddress(YxUserAddress yxUserAddress) {

        return yxUserAddressMapper.updateById(yxUserAddress);
    }
}
